package controllers

import (
	"gitee.com/ai-love-save/ai-love-save-back/app/service"
	"gitee.com/ai-love-save/ai-love-save-back/app/utils"
	"github.com/gin-gonic/gin"
	"github.com/google/wire"
	"go.uber.org/zap"
)

var UrlSet = wire.NewSet(wire.Struct(new(UrlGet), "*"))

type UrlGet struct {
	Logger *zap.Logger
	Util   *utils.Ginx
	List   service.LiveList
	Token  service.Tokendepend
}

type UrlGetSchema struct {
	PageStart string `json:"pageStart" default:"0"`
	PageSize  string `json:"pageSize" default:"10"`
}

func (u *UrlGet) GetUrl(c *gin.Context) {
	var data UrlGetSchema
	if err := u.Util.ParseJSON(c, &data); err != nil {
		u.Util.FailWarp(c, utils.ErrBodyCanNotParser)
		return
	}

	err, token := u.Token.RegetToken()
	if err != nil {
		u.Util.FailWarp(c, err)
		return
	}

	err, urlList := u.List.LiveList(token, data.PageStart, data.PageSize)
	if err != nil {
		u.Util.FailWarp(c, err)
		return
	}
	u.Util.SuccessWarp(c, urlList)
}
